use Test::More tests=> 18;

use strict;
use Data::Dumper;

use DateTime::Cursor;

# setup test data
my $time_0 = DateTime->now(time_zone => 'UTC');
my $iter_0 = DateTime::Cursor->new({pivot => $time_0});
sleep(1);
my $time_1 = DateTime->now(time_zone => 'UTC');
my $iter_1 = DateTime::Cursor->new({pivot => $time_1});

# test binary comparison
cmp_ok($iter_0, 'eq', $iter_0, 'iter 0 eq iter 0' );
cmp_ok($iter_0, 'ne', $iter_1, 'iter 0 ne iter 1' );
cmp_ok($iter_1, 'ne', $iter_0, 'iter 1 ne iter 0' );
cmp_ok($iter_0, 'eq', "$iter_0", 'iter 0 eq stringified iter 0');
cmp_ok("$iter_0", 'gt', "", 'stringified iter 0 greater than empty string');
cmp_ok($iter_0, '==', $iter_0, 'iter 0 == iter 0' );
cmp_ok($iter_0, '!=', $iter_1, 'iter 0 ne iter 1' );
cmp_ok($iter_1, '!=', $iter_0, 'iter 1 ne iter 0' );
cmp_ok(int $iter_0, '>', 0, 'numified iter 0 is gt 0');
cmp_ok($iter_0, '==', int $iter_0, 'iter 0 == numified iter 0');

my $numeric_compare = ($iter_0 <=> $iter_0);
is(0, $numeric_compare, "iter 0 <=> iter 0");
my $string_compare = ($iter_0 cmp $iter_0);
is(0, $string_compare, "iter 0 cmp iter 0");

$numeric_compare = ($iter_0 <=> $iter_1);
is(-1, $numeric_compare, "iter 0 <=> iter 1");
$string_compare = ($iter_0 cmp $iter_1);
is(-1, $string_compare, "iter 0 cmp iter 1");

$numeric_compare = ($iter_1 <=> $iter_0);
is(1, $numeric_compare, "iter 1 <=> iter 0");
$string_compare = ($iter_1 cmp $iter_0);
is(1, $string_compare, "iter 1 cmp iter 0");

# test sorting
my @unsorted = ($iter_1, $iter_0);
my @sorted = sort @unsorted;
ok(! eq_array(\@unsorted, \@sorted), "sorted and unsorted arrays are expected to be different");
is($sorted[0],$unsorted[1], "first cursor in sorted array is cursor 0");

